/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package webclient;

import com.sun.rave.web.ui.appbase.AbstractFragmentBean;
import com.sun.webui.jsf.component.DropDown;
import com.sun.webui.jsf.component.Label;
import com.sun.webui.jsf.component.RadioButtonGroup;
import com.sun.webui.jsf.model.SingleSelectOptionsList;
import javax.faces.FacesException;
import javax.faces.event.ValueChangeEvent;

/**
 * <p>Fragment bean that corresponds to a similarly named JSP page
 * fragment.  This class contains component definitions (and initialization
 * code) for all components that you have defined on this fragment, as well as
 * lifecycle methods and event handlers where you may add behavior
 * to respond to incoming events.</p>
 *
 * @version cuerpoCentral.java
 * @version Created on 04-abr-2009, 18:33:30
 */

public class cuerpoCentral extends AbstractFragmentBean {
    // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">

    /**
     * <p>Automatically managed component initialization. <strong>WARNING:</strong>
     * This method is automatically generated, so any user-specified code inserted
     * here is subject to being replaced.</p>
     */
    private void _init() throws Exception {
        radioButtonGroup1DefaultOptions.setOptions(new com.sun.webui.jsf.model.Option[]{new com.sun.webui.jsf.model.Option("soloida", "Sólo ida"), new com.sun.webui.jsf.model.Option("idavuelta", "Ida / Vuelta")});
        radioButtonGroup1DefaultOptions.setSelectedValue("idavuelta");
        dropDown3DefaultOptions.setOptions(new com.sun.webui.jsf.model.Option[]{new com.sun.webui.jsf.model.Option("Albacete", "Albacete"), new com.sun.webui.jsf.model.Option("Barcelona", "Barcelona"), new com.sun.webui.jsf.model.Option("Madrid", "Madrid"),new com.sun.webui.jsf.model.Option("Ciudad Real", "Ciudad Real"),new com.sun.webui.jsf.model.Option("Valencia", "Valencia"), new com.sun.webui.jsf.model.Option("Sevilla", "Sevilla"), new com.sun.webui.jsf.model.Option("A Coruña", "A Coruña"), new com.sun.webui.jsf.model.Option("Gijon", "Gijon"), new com.sun.webui.jsf.model.Option("Bilbao", "Bilbao"), new com.sun.webui.jsf.model.Option("Santander", "Santander"), new com.sun.webui.jsf.model.Option("Zaragoza", "Zaragoza")});
        dropDown1DefaultOptions.setOptions(new com.sun.webui.jsf.model.Option[]{new com.sun.webui.jsf.model.Option("Albacete", "Albacete"), new com.sun.webui.jsf.model.Option("Barcelona", "Barcelona"), new com.sun.webui.jsf.model.Option("Madrid", "Madrid"), new com.sun.webui.jsf.model.Option("Ciudad Real", "Ciudad Real"), new com.sun.webui.jsf.model.Option("Valencia", "Valencia")});
        dropDown2DefaultOptions.setOptions(new com.sun.webui.jsf.model.Option[]{new com.sun.webui.jsf.model.Option("Cualquiera", "Cualquiera"), new com.sun.webui.jsf.model.Option("Albacete", "Albacete"), new com.sun.webui.jsf.model.Option("Barcelona", "Barcelona"), new com.sun.webui.jsf.model.Option("Madrid", "Madrid"), new com.sun.webui.jsf.model.Option("Ciudad Real", "Ciudad Real"),new com.sun.webui.jsf.model.Option("Valencia", "Valencia")});
        dropDown2DefaultOptions.setSelectedValue("Cualquiera");
    }
    private SingleSelectOptionsList radioButtonGroup1DefaultOptions = new SingleSelectOptionsList();

    public SingleSelectOptionsList getRadioButtonGroup1DefaultOptions() {
        return radioButtonGroup1DefaultOptions;
    }

    public void setRadioButtonGroup1DefaultOptions(SingleSelectOptionsList ssol) {
        this.radioButtonGroup1DefaultOptions = ssol;
    }
    private SingleSelectOptionsList dropDown3DefaultOptions = new SingleSelectOptionsList();

    public SingleSelectOptionsList getDropDown3DefaultOptions() {
        return dropDown3DefaultOptions;
    }

    public void setDropDown3DefaultOptions(SingleSelectOptionsList ssol) {
        this.dropDown3DefaultOptions = ssol;
    }
    private SingleSelectOptionsList dropDown1DefaultOptions = new SingleSelectOptionsList();

    public SingleSelectOptionsList getDropDown1DefaultOptions() {
        return dropDown1DefaultOptions;
    }

    public void setDropDown1DefaultOptions(SingleSelectOptionsList ssol) {
        this.dropDown1DefaultOptions = ssol;
    }
    private SingleSelectOptionsList dropDown2DefaultOptions = new SingleSelectOptionsList();

    public SingleSelectOptionsList getDropDown2DefaultOptions() {
        return dropDown2DefaultOptions;
    }

    public void setDropDown2DefaultOptions(SingleSelectOptionsList ssol) {
        this.dropDown2DefaultOptions = ssol;
    }
    private Label label5 = new Label();

    public Label getLabel5() {
        return label5;
    }

    public void setLabel5(Label l) {
        this.label5 = l;
    }
    private RadioButtonGroup radioButtonGroup1 = new RadioButtonGroup();

    public RadioButtonGroup getRadioButtonGroup1() {
        return radioButtonGroup1;
    }

    public void setRadioButtonGroup1(RadioButtonGroup rbg) {
        this.radioButtonGroup1 = rbg;
    }
    private DropDown dropDown2 = new DropDown();

    public DropDown getDropDown2() {
        return dropDown2;
    }

    public void setDropDown2(DropDown dd) {
        this.dropDown2 = dd;
    }
    // </editor-fold>

    public cuerpoCentral() {
    }

    /**
     * <p>Callback method that is called whenever a page containing
     * this page fragment is navigated to, either directly via a URL,
     * or indirectly via page navigation.  Override this method to acquire
     * resources that will be needed for event handlers and lifecycle methods.</p>
     * 
     * <p>The default implementation does nothing.</p>
     */
    @Override
    public void init() {
        // Perform initializations inherited from our superclass
        super.init();

        try { // Call Web Service Operation
            gestionreservas.ReservaTrenesService service = new gestionreservas.ReservaTrenesService();
            gestionreservas.ReservaTrenes port = service.getReservaTrenesPort();
            // TODO process result here
            String origen=new String();
            if(this.dropDown2.getSelected()==null)
                origen="Cualquiera";
            else
                origen=this.dropDown2.getSelected().toString();
            java.util.List<gestionreservas.TrayectoClase> result = port.ofertas(origen);
            System.out.println(origen);
            System.out.println("Result = "+result);
            
            this.getSessionBean1().setListaT(new TrayectosDataProvider(result));
        } catch (Exception ex) {
            // TODO handle custom exceptions here
        }

        // Perform application initialization that must complete
        // *before* managed components are initialized
        // TODO - add your own initialiation code here
        
        
        // <editor-fold defaultstate="collapsed" desc="Visual-Web-managed Component Initialization">
        // Initialize automatically managed components
        // *Note* - this logic should NOT be modified
        try {
            _init();
        } catch (Exception e) {
            log("Page1 Initialization Failure", e);
            throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
        }
        
        // </editor-fold>
        // Perform application initialization that must complete
        // *after* managed components are initialized
        // TODO - add your own initialization code here
    }

    /**
     * <p>Callback method that is called after rendering is completed for
     * this request, if <code>init()</code> was called.  Override this
     * method to release resources acquired in the <code>init()</code>
     * resources that will be needed for event handlers and lifecycle methods.</p>
     * 
     * <p>The default implementation does nothing.</p>
     */
    @Override
    public void destroy() {
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected ApplicationBean1 getApplicationBean1() {
        return (ApplicationBean1) getBean("ApplicationBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected RequestBean1 getRequestBean1() {
        return (RequestBean1) getBean("RequestBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected SessionBean1 getSessionBean1() {
        return (SessionBean1) getBean("SessionBean1");
    }

    public void dropDown1_processValueChange(ValueChangeEvent event) {
        
    }

    public void radioButtonGroup1_processValueChange(ValueChangeEvent vce) {
        String sel=(String)this.radioButtonGroup1.getValue();
        if (sel.equals("idavuelta"))
            this.label5.setVisible(false);
       
        System.out.println(this.radioButtonGroup1.getValue());
    }

    public String button1_action() {
        // TODO: Process the action. Return value is a navigation
        // case name where null will return to the same page.
        return null;
    }

    public void dropDown2_processValueChange(ValueChangeEvent event) {
        System.out.println(this.dropDown2.getSelected());
        init();
    }

}
